package com.longge;

import java.util.HashMap;

public class CheckPermutation {
    public boolean CheckPermutation(String s1, String s2) {
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s1.length(); i++) {
            map.put(s1.charAt(i), map.getOrDefault(s1.charAt(i), 0) + 1);
        }
        for (int i = 0; i < s2.length(); i++) {
            Integer num = map.get(s2.charAt(i));
            if (num == null) return false;
            if (num - 1 == 0) {
                map.remove(s2.charAt(i));
            } else {
                map.put(s2.charAt(i), num - 1);
            }

        }
        return map.isEmpty();
    }
}
